//
//  InputGoldCountView.swift
//  Box
//
//  Created by mn on 2025/4/4.
//

import UIKit
import SnapKit

class InputGoldCountView: UIView {
    
    private let titleLabel: UILabel = {
        let label = UILabel()
        label.text = "其他金额"
        label.textColor = .fromHex("#001C00")
        label.font = UIFont.systemFont(ofSize: 18)
        return label
    }()
    
    private let separatorView: UIView = {
        let view = UIView()
        view.backgroundColor = .fromHex("#001C00")
        return view
    }()
    
    let textField: UITextField = {
        let textField = UITextField()
        textField.keyboardType = .numberPad
        textField.borderStyle = .none
        textField.backgroundColor = .clear
        textField.placeholder = "单位是元"
        return textField
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupView()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupView()
    }
    
    private func setupView() {
        backgroundColor = .fromHex("#F4F6F8")
        layer.cornerRadius = 18
        addSubview(titleLabel)
        addSubview(separatorView)
        addSubview(textField)
        textField.delegate = self
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
            make.width.equalTo(80)
        }
        
        separatorView.snp.makeConstraints { make in
            make.left.equalTo(titleLabel.snp.right).offset(6)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSizeMake(1, 20))
        }
        
        textField.snp.makeConstraints { make in
            make.left.equalTo(separatorView.snp.right).offset(8)
            make.right.equalToSuperview().offset(-16)
            make.top.bottom.equalToSuperview()
            make.width.greaterThanOrEqualTo(100)
        }
    }
    var beginEditing: (() -> Void)?
}
extension InputGoldCountView:UITextFieldDelegate{
    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        beginEditing?()
        return true
    }
}
